package sprites;

import java.awt.image.BufferedImage;

import com.golden.gamedev.object.Sprite;
import com.golden.gamedev.object.sprite.AdvanceSprite;
import com.golden.gamedev.object.sprite.VolatileSprite;

import engine.TowerDefense;

/**
 * Abstract class representing an entity in the game, such as a structure, an
 * enemy, or a treasure.
 * 
 * @author Alex Lee (hl69)
 */
public abstract class TDEntity extends AdvanceSprite
{

	/*
	 * All entities are owned by the game engine.
	 */
	TowerDefense myOwner;

	/*
	 * All entities have hitpoints.
	 */
	int hitpoints;

	/*
	 * 
	 */
	BufferedImage[] death;

	/**
	 * Creates a new TDEntity. 
	 * @param image the sprite image
	 * @param x x-coordinate
	 * @param y y-coordinate
	 */
	public TDEntity(TowerDefense owner, BufferedImage[] image,
			double x, double y)
	{
		super(image, x, y);

		myOwner = owner;
	}

	/**
	 * Damages the entity by the given amount.
	 * @param damage the amount of damage dealt
	 * @return remaining hitpoints
	 */
	public int damage(int damage)
	{
		hitpoints -= damage;
		return hitpoints;
	}

	/**
	 * Plays a death sprite.
	 */
	public void kill()
	{
		myOwner.field.add(new VolatileSprite(death, 0, 0));
	}

}
